//获取应用实例
var app = getApp()
Page({
  data: {

  },
  onLoad: function (e) {
    var that = this;
    if(e&&e.id){
      that.setData({
        id: e.id
      })
    }
    app.setNavtitle('中奖纪录');
    that.requestRecords();
  },
  requestRecords: function () {
    var that = this;
    var id = that.data.id;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_meeting_mine_lottery',
        id: id
      },
      success: function (res) {
        if (res.data.ec == 200) {
          console.log(res.data.data);
          that.setData({
            recordList: res.data.data.recordList
          })
        } else {
          console.log(res.data)
          app.errorTip(that, res.data.em, 2000);
          that.setData({
            recordList:[]
          })
        }
      },
      complete: function () {
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    });
  },
  onPullDownRefresh: function () {
    var that = this;
    that.requestRecords();
    console.log("下拉刷新");
  },
  copy: function (e) {
    var that = this;
    var data = e.target.dataset.code;
    wx.setClipboardData({
      data: data,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log(res.data) // data
            // app.errorTip(that, '成功复制到剪贴板', 3000);
          }
        })
      }
    })
  },
  copyCode:function(e){
    var code = e.currentTarget.dataset.code;
    wx.showActionSheet({
      itemList: ['复制兑换码'],
      success(res) {
        console.log(res.tapIndex)
        if (res.tapIndex==0){
          wx.setClipboardData({
            data: code,
            success: function (res0) {
              wx.getClipboardData({
                success: function (res1) {
                  console.log(res1.data)
                }
              })
            }
          })
        }
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
  //核销二维码显示
  codeModelShow: function (e) {
    var that = this;
    var record = e.currentTarget.dataset.record;
    that.setData({
      codeShow: true,
      curRecord: record
    })
  },
  //核销二维码弹窗关闭
  closeCodeModel: function () {
    var that = this;
    that.setData({
      codeShow: false
    })
  },
})

